<template>
  
  <div class="demo-pagination-block">

    <el-pagination
      v-model:current-page="currentPage"
      v-model:page-size="pageSize"
      :page-sizes="[5, 10, 15, 20]"
      :small="small"
      :disabled="disabled"
      :background="background"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>
<script lang="ts" setup>
import { ref, defineProps,defineEmits } from "vue";

const currentPage = ref(1);
const pageSize = ref(5);
const small = ref(false);
const background = ref(false);
const disabled = ref(false);
const props = defineProps(["total"]);
const emits = defineEmits(['current','pageSize'])
const handleSizeChange = (val: number) => {
  console.log("handleSizeChange")
  console.log(`${val} items per page`);
  let current=currentPage.value
  emits('pageSize',current,val)
};
const handleCurrentChange = (val: number) => {
 let size=pageSize.value
  emits('current',val,size)//触发transfer方法，this.value为向父组件传递的数据
};

//6.父组件访问子组件数据和方法，defineExpose()
defineExpose({
  pageSize,
  currentPage,
})
</script>

<style scoped>
.demo-pagination-block {
  margin-top: 10px;
  float: right;
}
.demo-pagination-block .demonstration {
  margin-bottom: 16px;
}
</style>
